/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package questao02;

import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.logging.Level;

/**
 *
 * @author SDKW
 */
public class LoggerFile implements Logger {
    private File file = null;
    private FileWriter writer = null;
    
    public LoggerFile() {
        try {
            file = new File("log.txt");
            file.createNewFile();
            writer = new FileWriter(file, true);
            
        } catch (IOException ex) {
            java.util.logging.Logger.getLogger(LoggerFile.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    
    @Override
    public void log(String log) {
        try {
            log = "\n" + log + "\n";
            writer.append(log);
            writer.flush();
        } catch (IOException ex) {
            java.util.logging.Logger.getLogger(LoggerFile.class.getName()).log(Level.SEVERE, null, ex);
        }     
    }

    @Override
    public void close() {
        try {
            writer.close();
        } catch (IOException ex) {
            java.util.logging.Logger.getLogger(LoggerFile.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    
}
